package com.example.android.ui.dialog

import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.View
import com.example.android.databinding.DialogMessageBinding
import com.zxf.basic.base.BindingDialog
import com.zxf.basic.expand.shapeDrawable
import com.zxf.basic.expand.signClick

/**
 * @author zjc
 * @date 2022/12/27
 */
class MessageDialog(ctx: Context, private val block: MessageDialog.(binding: DialogMessageBinding) -> Unit) : BindingDialog<DialogMessageBinding>(ctx, DialogMessageBinding::inflate) {

    var onNegativeClick: ((v: View) -> Unit)? = null
    var onPositiveClick: ((v: View) -> Unit)? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.also { block.invoke(this, it) }
        binding.apply {
            container.background = shapeDrawable {
                colors = intArrayOf(
                    Color.parseColor("#C451F8"),
                    Color.parseColor("#4140FD")
                )
                radiusTopLeft = 30f
                radiusTopRight = 30f
                radiusBottomLeft = 30f
                radiusBottomRight = 30f
            }
            tvCancel.signClick {
                dismiss()
                onNegativeClick?.invoke(it)
            }
            tvConfirm.signClick {
                dismiss()
                onPositiveClick?.invoke(it)
            }
            ivClose.signClick {
                dismiss()
            }
        }
    }

}